package com.spkj.srb.mybatisplus.controller;

import com.spkj.srb.mybatisplus.pojo.User;
import com.spkj.srb.mybatisplus.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.List;

/**
 * @author spkj
 * @create 2022-06-08 19:03
 */
@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/list")
    public List<User> list(HttpServletRequest request){
        String token = request.getHeader("token");
        if(!StringUtils.isEmpty(token)){
            String decode = "";
            try {
                decode = URLDecoder.decode(token, "utf-8");
                System.out.println("decode = " + decode);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        Cookie[] cookies = request.getCookies();
        System.out.println("cookies = " + cookies);
        return userService.list();
    }
}
